//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "uParametrages.h"
#include "uEtat.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "CBitBtn"
#pragma link "CEdit"
#pragma link "CUrlLbl"
#pragma link "CComboBx"
#pragma resource "*.dfm"
//---------------------------------------------------------------------------
#define MODULE_TAG MODULE_TAG_PARAMETRAGE

#define NB_METHODES 3
OLEMethode TfrmParametrages::OLETabMethode[NB_METHODES][OLE_Max+1]=
{
    {OLE_IViewObject2, OLE_IViewObject, OLE_IDataObject_EMF, OLE_IDataObject_WMF, OLE_IDataObject_GDI},
    {OLE_IDataObject_EMF, OLE_IDataObject_WMF, OLE_IDataObject_GDI, OLE_IViewObject2, OLE_IViewObject},
    {OLE_IDataObject_GDI, OLE_IDataObject_EMF, OLE_IDataObject_WMF, OLE_IViewObject2, OLE_IViewObject},
};
__fastcall TfrmParametrages::TfrmParametrages(TComponent* Owner)
    : TForm(Owner)
{
    chkActiverFichierEspion->Checked        = (Glob->TraceF == TRACEF_OK);

    chkAutoriseTextParBmp->Checked          = Glob->AutoriseTextParBmp;
    chkSortieTextesVerticauxParBmp->Checked = Glob->SortieTextesVerticauxParBmp;

    cbChoixOLE->Items->Clear();
    for( int i = 0; i < NB_METHODES; i++)
    {
        cbChoixOLE->Items->Add( RempliLibelleOLEMethode( OLETabMethode[i]));
        if( !memcmp( Glob->OLETabMethode, OLETabMethode[i], sizeof( OLETabMethode[i])) )
            cbChoixOLE->ItemIndex = i;
    }
    RefreshFicTrace();
}
//---------------------------------------------------------------------------
AnsiString __fastcall TfrmParametrages::RempliLibelleOLEMethode( const OLEMethode* TabMethode)
{
    AnsiString s;
    for( int i = 0; i <= OLE_Max; i++)
    {
        switch( TabMethode[ i])
        {
            case OLE_IViewObject2    : s += "IViewObject2"; break;
            case OLE_IViewObject     : s += "IViewObject"; break;
            case OLE_IDataObject_EMF : s += "EMF"; break;
            case OLE_IDataObject_WMF : s += "WMF"; break;
            case OLE_IDataObject_GDI : s += "GDI"; break;
        }
        if( i != OLE_Max)
            s += ";";
    }
    return s;
}

//---------------------------------------------------------------------------
typedef DWORD (__stdcall *fnGetLongPathName)( LPCTSTR lpszShortPath, LPTSTR lpszLongPath, DWORD cchBuffer);

void __fastcall TfrmParametrages::RefreshFicTrace()
{
    urlFicEspion->Enabled = FileExists( Glob->ficTrace);
    urlFicEspion->Url = AnsiString("mailto:support@eic.fr?subject=Problème d'édition"
                                   "&body= Suite au test d'impression, pensez à insérer le fichier : ") + Glob->ficTrace;

    if( urlFicEspion->Enabled)
    {
        HMODULE h = GetModuleHandle( "Kernel32.dll");
        fnGetLongPathName f = (fnGetLongPathName)::GetProcAddress( h, "GetLongPathNameA");
        if( f)
        {
            char* szBuff;
            int i;   
            ChkSDK( TAGL, (i = f(Glob->ficTrace, NULL, 0)), 1);
            szBuff = (char*)::_GlobalAlloc(TAGL, GPTR, i+1);
            ChkSDK( TAGL, f(Glob->ficTrace, szBuff, i), 0);
            edFichierEspion->Text = szBuff;
            ::_GlobalFree(TAGL, szBuff);
        }else
            edFichierEspion->Text = Glob->ficTrace;

    }else
        edFichierEspion->Text = Glob->ficTrace;
}
void __fastcall TfrmParametrages::btnOKClick(TObject *Sender)
{
    InitReg( true);
}
//---------------------------------------------------------------------------

void __fastcall TfrmParametrages::chkActiverFichierEspionClick(
      TObject *Sender)
{
    Glob->TraceF = chkActiverFichierEspion->Checked ? TRACEF_OK : TRACEF_Vide;
    InitReg( true);
    RefreshFicTrace();
}
//---------------------------------------------------------------------------

void __fastcall TfrmParametrages::chkAutoriseTextParBmpClick(TObject *Sender)
{
    Glob->AutoriseTextParBmp = chkAutoriseTextParBmp->Checked;
}
//---------------------------------------------------------------------------

void __fastcall TfrmParametrages::chkSortieTextesVerticauxParBmpClick(
      TObject *Sender)
{
    Glob->SortieTextesVerticauxParBmp = chkSortieTextesVerticauxParBmp->Checked;
}
//---------------------------------------------------------------------------

void __fastcall TfrmParametrages::cbChoixOLEChange(TObject *Sender)
{
    memcpy( Glob->OLETabMethode, OLETabMethode[cbChoixOLE->ItemIndex], sizeof(Glob->OLETabMethode));
}
//---------------------------------------------------------------------------

